﻿/**
 * jQuery EasyUI 1.2.4
 *
 * Licensed under the GPL terms
 * To use it on other terms please contact us
 *
 * Copyright(c) 2009-2011 stworthy [ stworthy@gmail.com ]
 *
 */
(function($) {
    function _1(_2) {
        var _3 = $.data(_2, "treegrid").options;
        $(_2).datagrid($.extend({}, _3, {
            url: null,
            onLoadSuccess: function() {
            },
            onResizeColumn: function(_4, _5) {
                _14(_2);
                _3.onResizeColumn.call(_2, _4, _5);
            },
            onSortColumn: function(_6, _7) {
                _3.sortName = _6;
                _3.sortOrder = _7;
                if (_3.remoteSort) {
                    _13(_2);
                } else {
                    var _8 = $(_2).treegrid("getData");
                    _3b(_2, 0, _8);
                }
                _3.onSortColumn.call(_2, _6, _7);
            },
            onBeforeEdit: function(_9, _a) {
                if (_3.onBeforeEdit.call(_2, _a) == false) {
                    return false;
                }
            },
            onAfterEdit: function(_b, _c, _d) {
                _28(_2);
                _3.onAfterEdit.call(_2, _c, _d);
            },
            onCancelEdit: function(_e, _f) {
                _28(_2);
                _3.onCancelEdit.call(_2, _f);
            }
        }));
        if (_3.pagination) {
            var _10 = $(_2).datagrid("getPager");
            _10.pagination({
                pageNumber: _3.pageNumber,
                pageSize: _3.pageSize,
                pageList: _3.pageList,
                onSelectPage: function(_11, _12) {
                    _3.pageNumber = _11;
                    _3.pageSize = _12;
                    _13(_2);
                }
            });
            _3.pageSize = _10.pagination("options").pageSize;
        }
    };
    function _14(_15, _16) {
        var _17 = $.data(_15, "datagrid").options;
        var _18 = $.data(_15, "datagrid").panel;
        var _19 = _18.children("div.datagrid-view");
        var _1a = _19.children("div.datagrid-view1");
        var _1b = _19.children("div.datagrid-view2");
        if (_17.rownumbers || (_17.frozenColumns && _17.frozenColumns.length > 0)) {
            if (_16) {
                _1c(_16);
                _1b.find("tr[node-id=" + _16 + "]").next("tr.treegrid-tr-tree").find("tr[node-id]").each(function() {
                    _1c($(this).attr("node-id"));
                });
            } else {
                _1b.find("tr[node-id]").each(function() {
                    _1c($(this).attr("node-id"));
                });
                if (_17.showFooter) {
                    var _1d = $.data(_15, "datagrid").footer || [];
                    for (var i = 0; i < _1d.length; i++) {
                        _1c(_1d[i][_17.idField]);
                    }
                    $(_15).datagrid("resize");
                }
            }
        }
        if (_17.height == "auto") {
            var _1e = _1a.children("div.datagrid-body");
            var _1f = _1b.children("div.datagrid-body");
            var _20 = 0;
            var _21 = 0;
            _1f.children().each(function() {
                var c = $(this);
                if (c.is(":visible")) {
                    _20 += c.outerHeight();
                    if (_21 < c.outerWidth()) {
                        _21 = c.outerWidth();
                    }
                }
            });
            if (_21 > _1f.width()) {
                _20 += 18;
            }
            _1e.height(_20);
            _1f.height(_20);
            _19.height(_1b.height());
        }
        _1b.children("div.datagrid-body").triggerHandler("scroll");
        function _1c(_22) {
            var tr1 = _1a.find("tr[node-id=" + _22 + "]");
            var tr2 = _1b.find("tr[node-id=" + _22 + "]");
            tr1.css("height", "");
            tr2.css("height", "");
            var _23 = Math.max(tr1.height(), tr2.height());
            tr1.css("height", _23);
            tr2.css("height", _23);
        };
            };
    function _24(_25) {
        var _26 = $.data(_25, "treegrid").options;
        if (!_26.rownumbers) {
            return;
        }
        $(_25).datagrid("getPanel").find("div.datagrid-view1 div.datagrid-body div.datagrid-cell-rownumber").each(function(i) {
            var _27 = i + 1;
            $(this).html(_27);
        });
    };
    function _28(_29) {
        var _2a = $.data(_29, "treegrid").options;
        var _2b = $(_29).datagrid("getPanel");
        var _2c = _2b.find("div.datagrid-body");
        _2c.find("span.tree-hit").unbind(".treegrid").bind("click.treegrid", function() {
            var tr = $(this).parent().parent().parent();
            var id = tr.attr("node-id");
            _94(_29, id);
            return false;
        }).bind("mouseenter.treegrid", function() {
            if ($(this).hasClass("tree-expanded")) {
                $(this).addClass("tree-expanded-hover");
            } else {
                $(this).addClass("tree-collapsed-hover");
            }
        }).bind("mouseleave.treegrid", function() {
            if ($(this).hasClass("tree-expanded")) {
                $(this).removeClass("tree-expanded-hover");
            } else {
                $(this).removeClass("tree-collapsed-hover");
            }
        });
        _2c.find("tr[node-id]").unbind(".treegrid").bind("mouseenter.treegrid", function() {
            var id = $(this).attr("node-id");
            _2c.find("tr[node-id=" + id + "]").addClass("datagrid-row-over");
        }).bind("mouseleave.treegrid", function() {
            var id = $(this).attr("node-id");
            _2c.find("tr[node-id=" + id + "]").removeClass("datagrid-row-over");
        }).bind("click.treegrid", function() {
            var id = $(this).attr("node-id");
            if (_2a.singleSelect) {
                _2f(_29);
                _7e(_29, id);
            } else {
                if ($(this).hasClass("datagrid-row-selected")) {
                    _82(_29, id);
                } else {
                    _7e(_29, id);
                }
            }
            _2a.onClickRow.call(_29, _46(_29, id));
        }).bind("dblclick.treegrid", function() {
            var id = $(this).attr("node-id");
            _2a.onDblClickRow.call(_29, _46(_29, id));
        }).bind("contextmenu.treegrid", function(e) {
            var id = $(this).attr("node-id");
            _2a.onContextMenu.call(_29, e, _46(_29, id));
        });
        _2c.find("div.datagrid-cell-check input[type=checkbox]").unbind(".treegrid").bind("click.treegrid", function(e) {
            var id = $(this).parent().parent().parent().attr("node-id");
            if (_2a.singleSelect) {
                _2f(_29);
                _7e(_29, id);
            } else {
                if ($(this).attr("checked")) {
                    _7e(_29, id);
                } else {
                    _82(_29, id);
                }
            }
            e.stopPropagation();
        });
        var _2d = _2b.find("div.datagrid-header");
        _2d.find("input[type=checkbox]").unbind().bind("click.treegrid", function() {
            if (_2a.singleSelect) {
                return false;
            }
            if ($(this).attr("checked")) {
                _2e(_29);
            } else {
                _2f(_29);
            }
        });
    };
    function _30(_31, _32) {
        var _33 = $.data(_31, "treegrid").options;
        var _34 = $(_31).datagrid("getPanel").children("div.datagrid-view");
        var _35 = _34.children("div.datagrid-view1");
        var _36 = _34.children("div.datagrid-view2");
        var tr1 = _35.children("div.datagrid-body").find("tr[node-id=" + _32 + "]");
        var tr2 = _36.children("div.datagrid-body").find("tr[node-id=" + _32 + "]");
        var _37 = $(_31).datagrid("getColumnFields", true).length + (_33.rownumbers ? 1 : 0);
        var _38 = $(_31).datagrid("getColumnFields", false).length;
        _39(tr1, _37);
        _39(tr2, _38);
        function _39(tr, _3a) {
            $("<tr class=\"treegrid-tr-tree\">" + "<td style=\"border:0px\" colspan=\"" + _3a + "\">" + "<div></div>" + "</td>" + "</tr>").insertAfter(tr);
        };
            };
    function _3b(_3c, _3d, _3e, _3f) {
        var _40 = $.data(_3c, "treegrid").options;
        _3e = _40.loadFilter.call(_3c, _3e, _3d);
        var _41 = $.data(_3c, "datagrid").panel;
        var _42 = _41.children("div.datagrid-view");
        var _43 = _42.children("div.datagrid-view1");
        var _44 = _42.children("div.datagrid-view2");
        var _45 = _46(_3c, _3d);
        if (_45) {
            var _47 = _43.children("div.datagrid-body").find("tr[node-id=" + _3d + "]");
            var _48 = _44.children("div.datagrid-body").find("tr[node-id=" + _3d + "]");
            var cc1 = _47.next("tr.treegrid-tr-tree").children("td").children("div");
            var cc2 = _48.next("tr.treegrid-tr-tree").children("td").children("div");
        } else {
            var cc1 = _43.children("div.datagrid-body").children("div.datagrid-body-inner");
            var cc2 = _44.children("div.datagrid-body");
        }
        if (!_3f) {
            $.data(_3c, "treegrid").data = [];
            cc1.empty();
            cc2.empty();
        }
        if (_40.view.onBeforeRender) {
            _40.view.onBeforeRender.call(_40.view, _3c, _3d, _3e);
        }
        _40.view.render.call(_40.view, _3c, cc1, true);
        _40.view.render.call(_40.view, _3c, cc2, false);
        if (_40.showFooter) {
            _40.view.renderFooter.call(_40.view, _3c, _43.find("div.datagrid-footer-inner"), true);
            _40.view.renderFooter.call(_40.view, _3c, _44.find("div.datagrid-footer-inner"), false);
        }
        if (_40.view.onAfterRender) {
            _40.view.onAfterRender.call(_40.view, _3c);
        }
        _40.onLoadSuccess.call(_3c, _45, _3e);
        if (!_3d && _40.pagination) {
            var _49 = $.data(_3c, "treegrid").total;
            var _4a = $(_3c).datagrid("getPager");
            if (_4a.pagination("options").total != _49) {
                _4a.pagination({
                    total: _49
                });
            }
        }
        _14(_3c);
        _24(_3c);
        _4b();
        _28(_3c);
        function _4b() {
            var _4c = _42.find("div.datagrid-header");
            var _4d = _42.find("div.datagrid-body");
            var _4e = _4c.find("div.datagrid-header-check");
            if (_4e.length) {
                var ck = _4d.find("div.datagrid-cell-check");
                if ($.boxModel) {
                    ck.width(_4e.width());
                    ck.height(_4e.height());
                } else {
                    ck.width(_4e.outerWidth());
                    ck.height(_4e.outerHeight());
                }
            }
        };
            };
    function tranData(list) {
        for (var i = 0; i < list.length; i++) {
            for (j in list[i].attributes) {
                list[i][j] = list[i].attributes[j];
            }
            if (list[i].children && list[i].children.length > 0) {
                tranData(list[i].children);
            }
        }
        return list;
    }
    function _13(_4f, _50, _51, _52, _53) {
        var _54 = $.data(_4f, "treegrid").options;
        var _55 = $(_4f).datagrid("getPanel").find("div.datagrid-body");
        if (_51) {
            _54.queryParams = _51;
        }
        var _56 = $.extend({}, _54.queryParams);
        if (_54.pagination) {
            $.extend(_56, {
                page: _54.pageNumber,
                rows: _54.pageSize
            });
        }
        if (_54.sortName) {
            $.extend(_56, {
                sort: _54.sortName,
                order: _54.sortOrder
            });
        }
        var row = _46(_4f, _50);
        if (_54.onBeforeLoad.call(_4f, row, _56) == false) {
            return;
        }
        if (!_54.url) {
            return;
        }
        var _57 = _55.find("tr[node-id=" + _50 + "] span.tree-folder");
        _57.addClass("tree-loading");
        $(_4f).treegrid("loading");
        $.ajax({
            type: _54.method,
            url: _54.url,
            data: _56,
            dataType: "json",
            success: function(_58) {
                _57.removeClass("tree-loading");
                $(_4f).treegrid("loaded");
                if (_58.success) {
					var list = tranData(_58.result);
                	_3b(_4f, _50, list, _52);
                    if (_53) {
                        _53();
                    }
                } else {
                    _54.onLoadError.apply(_4f, arguments);
                    if (_53) {
                        _53();
                    }
                    $.messager.show({
                        msg: result.msg
                    });
                }
            },
            error: function() {
                _57.removeClass("tree-loading");
                $(_4f).treegrid("loaded");
                _54.onLoadError.apply(_4f, arguments);
                if (_53) {
                    _53();
                }
            }
        });
    };
    function _59(_5a) {
        var _5b = _5c(_5a);
        if (_5b.length) {
            return _5b[0];
        } else {
            return null;
        }
    };
    function _5c(_5d) {
        return $.data(_5d, "treegrid").data;
    };
    function _5e(_5f, _60) {
        var row = _46(_5f, _60);
        if (row._parentId) {
            return _46(_5f, row._parentId);
        } else {
            return null;
        }
    };
    function _61(_62, _63) {
        var _64 = $.data(_62, "treegrid").options;
        var _65 = $(_62).datagrid("getPanel").find("div.datagrid-view2 div.datagrid-body");
        var _66 = [];
        if (_63) {
            _67(_63);
        } else {
            var _68 = _5c(_62);
            for (var i = 0; i < _68.length; i++) {
                _66.push(_68[i]);
                _67(_68[i][_64.idField]);
            }
        }
        function _67(_69) {
            var _6a = _46(_62, _69);
            if (_6a && _6a.children) {
                for (var i = 0, len = _6a.children.length; i < len; i++) {
                    var _6b = _6a.children[i];
                    _66.push(_6b);
                    _67(_6b[_64.idField]);
                }
            }
        };
        return _66;
    };
    function _6c(_6d) {
        var _6e = _6f(_6d);
        if (_6e.length) {
            return _6e[0];
        } else {
            return null;
        }
    };
    function _6f(_70) {
        var _71 = [];
        var _72 = $(_70).datagrid("getPanel");
        _72.find("div.datagrid-view2 div.datagrid-body tr.datagrid-row-selected").each(function() {
            var id = $(this).attr("node-id");
            _71.push(_46(_70, id));
        });
        return _71;
    };
    function _73(_74, _75) {
        if (!_75) {
            return 0;
        }
        var _76 = $.data(_74, "treegrid").options;
        var _77 = $(_74).datagrid("getPanel").children("div.datagrid-view");
        var _78 = _77.find("div.datagrid-body tr[node-id=" + _75 + "]").children("td[field=" + _76.treeField + "]");
        return _78.find("span.tree-indent,span.tree-hit").length;
    };
    function _46(_79, _7a) {
        var _7b = $.data(_79, "treegrid").options;
        var _7c = $.data(_79, "treegrid").data;
        var cc = [_7c];
        while (cc.length) {
            var c = cc.shift();
            for (var i = 0; i < c.length; i++) {
                var _7d = c[i];
                if (_7d[_7b.idField] == _7a) {
                    return _7d;
                } else {
                    if (_7d["children"]) {
                        cc.push(_7d["children"]);
                    }
                }
            }
        }
        return null;
    };
    function _7e(_7f, _80) {
        var _81 = $(_7f).datagrid("getPanel").find("div.datagrid-body");
        var tr = _81.find("tr[node-id=" + _80 + "]");
        tr.addClass("datagrid-row-selected");
        tr.find("div.datagrid-cell-check input[type=checkbox]").attr("checked", true);
    };
    function _82(_83, _84) {
        var _85 = $(_83).datagrid("getPanel").find("div.datagrid-body");
        var tr = _85.find("tr[node-id=" + _84 + "]");
        tr.removeClass("datagrid-row-selected");
        tr.find("div.datagrid-cell-check input[type=checkbox]").attr("checked", false);
    };
    function _2e(_86) {
        var tr = $(_86).datagrid("getPanel").find("div.datagrid-body tr[node-id]");
        tr.addClass("datagrid-row-selected");
        tr.find("div.datagrid-cell-check input[type=checkbox]").attr("checked", true);
    };
    function _2f(_87) {
        var tr = $(_87).datagrid("getPanel").find("div.datagrid-body tr[node-id]");
        tr.removeClass("datagrid-row-selected");
        tr.find("div.datagrid-cell-check input[type=checkbox]").attr("checked", false);
    };
    function _88(_89, _8a) {
        var _8b = $.data(_89, "treegrid").options;
        var _8c = $(_89).datagrid("getPanel").find("div.datagrid-body");
        var row = _46(_89, _8a);
        var tr = _8c.find("tr[node-id=" + _8a + "]");
        var hit = tr.find("span.tree-hit");
        if (hit.length == 0) {
            return;
        }
        if (hit.hasClass("tree-collapsed")) {
            return;
        }
        if (_8b.onBeforeCollapse.call(_89, row) == false) {
            return;
        }
        hit.removeClass("tree-expanded tree-expanded-hover").addClass("tree-collapsed");
        hit.next().removeClass("tree-folder-open");
        row.state = "closed";
        tr = tr.next("tr.treegrid-tr-tree");
        var cc = tr.children("td").children("div");
        if (_8b.animate) {
            cc.slideUp("normal", function() {
                _14(_89, _8a);
                _8b.onCollapse.call(_89, row);
            });
        } else {
            cc.hide();
            _14(_89, _8a);
            _8b.onCollapse.call(_89, row);
        }
    };
    function _8d(_8e, _8f) {
        var _90 = $.data(_8e, "treegrid").options;
        var _91 = $(_8e).datagrid("getPanel").find("div.datagrid-body");
        var tr = _91.find("tr[node-id=" + _8f + "]");
        var hit = tr.find("span.tree-hit");
        var row = _46(_8e, _8f);
        if (hit.length == 0) {
            return;
        }
        if (hit.hasClass("tree-expanded")) {
            return;
        }
        if (_90.onBeforeExpand.call(_8e, row) == false) {
            return;
        }
        hit.removeClass("tree-collapsed tree-collapsed-hover").addClass("tree-expanded");
        hit.next().addClass("tree-folder-open");
        var _92 = tr.next("tr.treegrid-tr-tree");
        if (_92.length) {
            var cc = _92.children("td").children("div");
            _93(cc);
        } else {
            _30(_8e, row[_90.idField]);
            var _92 = tr.next("tr.treegrid-tr-tree");
            var cc = _92.children("td").children("div");
            cc.hide();
            _13(_8e, row[_90.idField], {
                id: row[_90.idField]
            }, true, function() {
                _93(cc);
            });
        }
        function _93(cc) {
            row.state = "open";
            if (_90.animate) {
                cc.slideDown("normal", function() {
                    _14(_8e, _8f);
                    _90.onExpand.call(_8e, row);
                });
            } else {
                cc.show();
                _14(_8e, _8f);
                _90.onExpand.call(_8e, row);
            }
        };
            };
    function _94(_95, _96) {
        var _97 = $(_95).datagrid("getPanel").find("div.datagrid-body");
        var tr = _97.find("tr[node-id=" + _96 + "]");
        var hit = tr.find("span.tree-hit");
        if (hit.hasClass("tree-expanded")) {
            _88(_95, _96);
        } else {
            _8d(_95, _96);
        }
    };
    function _98(_99, _9a) {
        var _9b = $.data(_99, "treegrid").options;
        var _9c = _61(_99, _9a);
        if (_9a) {
            _9c.unshift(_46(_99, _9a));
        }
        for (var i = 0; i < _9c.length; i++) {
            _88(_99, _9c[i][_9b.idField]);
        }
    };
    function _9d(_9e, _9f) {
        var _a0 = $.data(_9e, "treegrid").options;
        var _a1 = _61(_9e, _9f);
        if (_9f) {
            _a1.unshift(_46(_9e, _9f));
        }
        for (var i = 0; i < _a1.length; i++) {
            _8d(_9e, _a1[i][_a0.idField]);
        }
    };
    function _a2(_a3, _a4) {
        var _a5 = $.data(_a3, "treegrid").options;
        var ids = [];
        var p = _5e(_a3, _a4);
        while (p) {
            var id = p[_a5.idField];
            ids.unshift(id);
            p = _5e(_a3, id);
        }
        for (var i = 0; i < ids.length; i++) {
            _8d(_a3, ids[i]);
        }
    };
    function _a6(_a7, _a8) {
        var _a9 = $.data(_a7, "treegrid").options;
        if (_a8.parent) {
            var _aa = $(_a7).datagrid("getPanel").find("div.datagrid-body");
            var tr = _aa.find("tr[node-id=" + _a8.parent + "]");
            if (tr.next("tr.treegrid-tr-tree").length == 0) {
                _30(_a7, _a8.parent);
            }
            var _ab = tr.children("td[field=" + _a9.treeField + "]").children("div.datagrid-cell");
            var _ac = _ab.children("span.tree-icon");
            if (_ac.hasClass("tree-file")) {
                _ac.removeClass("tree-file").addClass("tree-folder");
                var hit = $("<span class=\"tree-hit tree-expanded\"></span>").insertBefore(_ac);
                if (hit.prev().length) {
                    hit.prev().remove();
                }
            }
        }
        _3b(_a7, _a8.parent, _a8.data, true);
    };
    function _ad(_ae, _af) {
        var _b0 = $.data(_ae, "treegrid").options;
        var _b1 = $(_ae).datagrid("getPanel").find("div.datagrid-body");
        var tr = _b1.find("tr[node-id=" + _af + "]");
        tr.next("tr.treegrid-tr-tree").remove();
        tr.remove();
        var _b2 = del(_af);
        if (_b2) {
            if (_b2.children.length == 0) {
                tr = _b1.find("tr[node-id=" + _b2[_b0.treeField] + "]");
                var _b3 = tr.children("td[field=" + _b0.treeField + "]").children("div.datagrid-cell");
                _b3.find(".tree-icon").removeClass("tree-folder").addClass("tree-file");
                _b3.find(".tree-hit").remove();
                $("<span class=\"tree-indent\"></span>").prependTo(_b3);
            }
        }
        _24(_ae);
        function del(id) {
            var cc;
            var _b4 = _5e(_ae, _af);
            if (_b4) {
                cc = _b4.children;
            } else {
                cc = $(_ae).treegrid("getData");
            }
            for (var i = 0; i < cc.length; i++) {
                if (cc[i][_b0.treeField] == id) {
                    cc.splice(i, 1);
                    break;
                }
            }
            return _b4;
        };
            };
    $.fn.treegrid = function(_b5, _b6) {
        if (typeof _b5 == "string") {
            var _b7 = $.fn.treegrid.methods[_b5];
            if (_b7) {
                return _b7(this, _b6);
            } else {
                return this.datagrid(_b5, _b6);
            }
        }
        _b5 = _b5 || {};
        return this.each(function() {
            var _b8 = $.data(this, "treegrid");
            if (_b8) {
                $.extend(_b8.options, _b5);
            } else {
                $.data(this, "treegrid", {
                    options: $.extend({}, $.fn.treegrid.defaults, $.fn.treegrid.parseOptions(this), _b5),
                    data: []
                });
            }
            _1(this);
            _13(this);
        });
    };
    $.fn.treegrid.methods = {
        options: function(jq) {
            return $.data(jq[0], "treegrid").options;
        },
        resize: function(jq, _b9) {
            return jq.each(function() {
                $(this).datagrid("resize", _b9);
            });
        },
        fixRowHeight: function(jq, _ba) {
            return jq.each(function() {
                _14(this, _ba);
            });
        },
        loadData: function(jq, _bb) {
            return jq.each(function() {
                _3b(this, null, _bb);
            });
        },
        reload: function(jq, id) {
            return jq.each(function() {
                if (id) {
                    var _bc = $(this).treegrid("find", id);
                    if (_bc.children) {
                        _bc.children.splice(0, _bc.children.length);
                    }
                    var _bd = $(this).datagrid("getPanel").find("div.datagrid-body");
                    var tr = _bd.find("tr[node-id=" + id + "]");
                    tr.next("tr.treegrid-tr-tree").remove();
                    var hit = tr.find("span.tree-hit");
                    hit.removeClass("tree-expanded tree-expanded-hover").addClass("tree-collapsed");
                    _8d(this, id);
                } else {
                    _13(this, null, {});
                }
            });
        },
        reloadFooter: function(jq, _be) {
            return jq.each(function() {
                var _bf = $.data(this, "treegrid").options;
                var _c0 = $(this).datagrid("getPanel").children("div.datagrid-view");
                var _c1 = _c0.children("div.datagrid-view1");
                var _c2 = _c0.children("div.datagrid-view2");
                if (_be) {
                    $.data(this, "treegrid").footer = _be;
                }
                if (_bf.showFooter) {
                    _bf.view.renderFooter.call(_bf.view, this, _c1.find("div.datagrid-footer-inner"), true);
                    _bf.view.renderFooter.call(_bf.view, this, _c2.find("div.datagrid-footer-inner"), false);
                    if (_bf.view.onAfterRender) {
                        _bf.view.onAfterRender.call(_bf.view, this);
                    }
                    $(this).treegrid("fixRowHeight");
                }
            });
        },
        loading: function(jq) {
            return jq.each(function() {
                $(this).datagrid("loading");
            });
        },
        loaded: function(jq) {
            return jq.each(function() {
                $(this).datagrid("loaded");
            });
        },
        getData: function(jq) {
            return $.data(jq[0], "treegrid").data;
        },
        getFooterRows: function(jq) {
            return $.data(jq[0], "treegrid").footer;
        },
        getRoot: function(jq) {
            return _59(jq[0]);
        },
        getRoots: function(jq) {
            return _5c(jq[0]);
        },
        getParent: function(jq, id) {
            return _5e(jq[0], id);
        },
        getChildren: function(jq, id) {
            return _61(jq[0], id);
        },
        getSelected: function(jq) {
            return _6c(jq[0]);
        },
        getSelections: function(jq) {
            return _6f(jq[0]);
        },
        getLevel: function(jq, id) {
            return _73(jq[0], id);
        },
        find: function(jq, id) {
            return _46(jq[0], id);
        },
        isLeaf: function(jq, id) {
            var _c3 = $.data(jq[0], "treegrid").options;
            var tr = _c3.editConfig.getTr(jq[0], id);
            var hit = tr.find("span.tree-hit");
            return hit.length == 0;
        },
        select: function(jq, id) {
            return jq.each(function() {
                _7e(this, id);
            });
        },
        unselect: function(jq, id) {
            return jq.each(function() {
                _82(this, id);
            });
        },
        selectAll: function(jq) {
            return jq.each(function() {
                _2e(this);
            });
        },
        unselectAll: function(jq) {
            return jq.each(function() {
                _2f(this);
            });
        },
        collapse: function(jq, id) {
            return jq.each(function() {
                _88(this, id);
            });
        },
        expand: function(jq, id) {
            return jq.each(function() {
                _8d(this, id);
            });
        },
        toggle: function(jq, id) {
            return jq.each(function() {
                _94(this, id);
            });
        },
        collapseAll: function(jq, id) {
            return jq.each(function() {
                _98(this, id);
            });
        },
        expandAll: function(jq, id) {
            return jq.each(function() {
                _9d(this, id);
            });
        },
        expandTo: function(jq, id) {
            return jq.each(function() {
                _a2(this, id);
            });
        },
        append: function(jq, _c4) {
            return jq.each(function() {
                _a6(this, _c4);
            });
        },
        remove: function(jq, id) {
            return jq.each(function() {
                _ad(this, id);
            });
        },
        refresh: function(jq, id) {
            return jq.each(function() {
                var _c5 = $.data(this, "treegrid").options;
                _c5.view.refreshRow.call(_c5.view, this, id);
            });
        },
        beginEdit: function(jq, id) {
            return jq.each(function() {
                $(this).datagrid("beginEdit", id);
                $(this).treegrid("fixRowHeight", id);
            });
        },
        endEdit: function(jq, id) {
            return jq.each(function() {
                $(this).datagrid("endEdit", id);
            });
        },
        cancelEdit: function(jq, id) {
            return jq.each(function() {
                $(this).datagrid("cancelEdit", id);
            });
        }
    };
    $.fn.treegrid.parseOptions = function(_c6) {
        var t = $(_c6);
        return $.extend({}, $.fn.datagrid.parseOptions(_c6), {
            treeField: t.attr("treeField"),
            animate: (t.attr("animate") ? t.attr("animate") == "true" : undefined)
        });
    };
    var _c7 = $.extend({}, $.fn.datagrid.defaults.view, {
        render: function(_c8, _c9, _ca) {
            var _cb = $.data(_c8, "treegrid").options;
            var _cc = $(_c8).datagrid("getColumnFields", _ca);
            var _cd = this;
            var _ce = _cf(_ca, this.treeLevel, this.treeNodes);
            $(_c9).append(_ce.join(""));
            function _cf(_d0, _d1, _d2) {
                var _d3 = ["<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody>"];
                for (var i = 0; i < _d2.length; i++) {
                    var row = _d2[i];
                    if (row.state != "open" && row.state != "closed") {
                        row.state = "open";
                    }
                    var _d4 = _cb.rowStyler ? _cb.rowStyler.call(_c8, row) : "";
                    var _d5 = _d4 ? "style=\"" + _d4 + "\"" : "";
                    _d3.push("<tr node-id=" + row[_cb.idField] + " " + _d5 + ">");
                    _d3 = _d3.concat(_cd.renderRow.call(_cd, _c8, _cc, _d0, _d1, row));
                    _d3.push("</tr>");
                    if (row.children && row.children.length) {
                        var tt = _cf(_d0, _d1 + 1, row.children);
                        var v = row.state == "closed" ? "none" : "block";
                        _d3.push("<tr class=\"treegrid-tr-tree\"><td style=\"border:0px\" colspan=" + (_cc.length + (_cb.rownumbers ? 1 : 0)) + "><div style=\"display:" + v + "\">");
                        _d3 = _d3.concat(tt);
                        _d3.push("</div></td></tr>");
                    }
                }
                _d3.push("</tbody></table>");
                return _d3;
            };
                    },
        renderFooter: function(_d6, _d7, _d8) {
            var _d9 = $.data(_d6, "treegrid").options;
            var _da = $.data(_d6, "treegrid").footer || [];
            var _db = $(_d6).datagrid("getColumnFields", _d8);
            var _dc = ["<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody>"];
            for (var i = 0; i < _da.length; i++) {
                var row = _da[i];
                row[_d9.idField] = row[_d9.idField] || ("foot-row-id" + i);
                _dc.push("<tr node-id=" + row[_d9.idField] + ">");
                _dc.push(this.renderRow.call(this, _d6, _db, _d8, 0, row));
                _dc.push("</tr>");
            }
            _dc.push("</tbody></table>");
            $(_d7).html(_dc.join(""));
        },
        renderRow: function(_dd, _de, _df, _e0, row) {
            var _e1 = $.data(_dd, "treegrid").options;
            var cc = [];
            if (_df && _e1.rownumbers) {
                cc.push("<td class=\"datagrid-td-rownumber\"><div class=\"datagrid-cell-rownumber\">0</div></td>");
            }
            for (var i = 0; i < _de.length; i++) {
                var _e2 = _de[i];
                var col = $(_dd).datagrid("getColumnOption", _e2);
                if (col) {
                    var _e3 = col.styler ? (col.styler(row[_e2], row) || "") : "";
                    var _e4 = col.hidden ? "style=\"display:none;" + _e3 + "\"" : (_e3 ? "style=\"" + _e3 + "\"" : "");
                    cc.push("<td field=\"" + _e2 + "\" " + _e4 + ">");
                    var _e4 = "width:" + (col.boxWidth) + "px;";
                    _e4 += "text-align:" + (col.align || "left") + ";";
                    _e4 += _e1.nowrap == false ? "white-space:normal;" : "";
                    cc.push("<div style=\"" + _e4 + "\" ");
                    if (col.checkbox) {
                        cc.push("class=\"datagrid-cell-check ");
                    } else {
                        cc.push("class=\"datagrid-cell ");
                    }
                    cc.push("\">");
                    if (col.checkbox) {
                        if (row.checked) {
                            cc.push("<input type=\"checkbox\" checked=\"checked\"/>");
                        } else {
                            cc.push("<input type=\"checkbox\"/>");
                        }
                    } else {
                        var val = null;
                        if (col.formatter) {
                            val = col.formatter(row[_e2], row);
                        } else {
                            val = row[_e2] || "&nbsp;";
                        }
                        if (_e2 == _e1.treeField) {
                            for (var j = 0; j < _e0; j++) {
                                cc.push("<span class=\"tree-indent\"></span>");
                            }
                            if (row.state == "closed") {
                                cc.push("<span class=\"tree-hit tree-collapsed\"></span>");
                                cc.push("<span class=\"tree-icon tree-folder " + (row.iconCls ? row.iconCls : "") + "\"></span>");
                            } else {
                                if (row.children && row.children.length) {
                                    cc.push("<span class=\"tree-hit tree-expanded\"></span>");
                                    cc.push("<span class=\"tree-icon tree-folder tree-folder-open " + (row.iconCls ? row.iconCls : "") + "\"></span>");
                                } else {
                                    cc.push("<span class=\"tree-indent\"></span>");
                                    cc.push("<span class=\"tree-icon tree-file " + (row.iconCls ? row.iconCls : "") + "\"></span>");
                                }
                            }
                            cc.push("<span class=\"tree-title\">" + val + "</span>");
                        } else {
                            cc.push(val);
                        }
                    }
                    cc.push("</div>");
                    cc.push("</td>");
                }
            }
            return cc.join("");
        },
        refreshRow: function(_e5, id) {
            var row = $(_e5).treegrid("find", id);
            var _e6 = $.data(_e5, "treegrid").options;
            var _e7 = $(_e5).datagrid("getPanel").find("div.datagrid-body");
            var _e8 = _e6.rowStyler ? _e6.rowStyler.call(_e5, row) : "";
            var _e9 = _e8 ? _e8 : "";
            var tr = _e7.find("tr[node-id=" + id + "]");
            tr.attr("style", _e9);
            tr.children("td").each(function() {
                var _ea = $(this).find("div.datagrid-cell");
                var _eb = $(this).attr("field");
                var col = $(_e5).datagrid("getColumnOption", _eb);
                if (col) {
                    var _ec = col.styler ? (col.styler(row[_eb], row) || "") : "";
                    var _ed = col.hidden ? "display:none;" + _ec : (_ec ? _ec : "");
                    $(this).attr("style", _ed);
                    var val = null;
                    if (col.formatter) {
                        val = col.formatter(row[_eb], row);
                    } else {
                        val = row[_eb] || "&nbsp;";
                    }
                    if (_eb == _e6.treeField) {
                        _ea.children("span.tree-title").html(val);
                        var cls = "tree-icon";
                        var _ee = _ea.children("span.tree-icon");
                        if (_ee.hasClass("tree-folder")) {
                            cls += " tree-folder";
                        }
                        if (_ee.hasClass("tree-folder-open")) {
                            cls += " tree-folder-open";
                        }
                        if (_ee.hasClass("tree-file")) {
                            cls += " tree-file";
                        }
                        if (row.iconCls) {
                            cls += " " + row.iconCls;
                        }
                        _ee.attr("class", cls);
                    } else {
                        _ea.html(val);
                    }
                }
            });
            $(_e5).treegrid("fixRowHeight", id);
        },
        onBeforeRender: function(_ef, _f0, _f1) {
            if (!_f1) {
                return false;
            }
            var _f2 = $.data(_ef, "treegrid").options;
            if (_f1.length == undefined) {
                if (_f1.footer) {
                    $.data(_ef, "treegrid").footer = _f1.footer;
                }
                if (_f1.total) {
                    $.data(_ef, "treegrid").total = _f1.total;
                }
                _f1 = this.transfer(_ef, _f0, _f1.rows);
            } else {
                function _f3(_f4, _f5) {
                    for (var i = 0; i < _f4.length; i++) {
                        var row = _f4[i];
                        row._parentId = _f5;
                        if (row.children && row.children.length) {
                            _f3(row.children, row[_f2.idField]);
                        }
                    }
                };
                _f3(_f1, _f0);
            }
            var _f6 = _46(_ef, _f0);
            if (_f6) {
                if (_f6.children) {
                    _f6.children = _f6.children.concat(_f1);
                } else {
                    _f6.children = _f1;
                }
            } else {
                $.data(_ef, "treegrid").data = $.data(_ef, "treegrid").data.concat(_f1);
            }
            if (!_f2.remoteSort) {
                this.sort(_ef, _f1);
            }
            this.treeNodes = _f1;
            this.treeLevel = $(_ef).treegrid("getLevel", _f0);
        },
        sort: function(_f7, _f8) {
            var _f9 = $.data(_f7, "treegrid").options;
            var opt = $(_f7).treegrid("getColumnOption", _f9.sortName);
            if (opt) {
                var _fa = opt.sorter ||
                function(a, b) {
                    return (a > b ? 1 : -1);
                };
                _fb(_f8);
            }
            function _fb(_fc) {
                _fc.sort(function(r1, r2) {
                    return _fa(r1[_f9.sortName], r2[_f9.sortName]) * (_f9.sortOrder == "asc" ? 1 : -1);
                });
                for (var i = 0; i < _fc.length; i++) {
                    var _fd = _fc[i].children;
                    if (_fd && _fd.length) {
                        _fb(_fd);
                    }
                }
            };
                    },
        transfer: function(_fe, _ff, data) {
            var opts = $.data(_fe, "treegrid").options;
            var rows = [];
            for (var i = 0; i < data.length; i++) {
                rows.push(data[i]);
            }
            var _100 = [];
            for (var i = 0; i < rows.length; i++) {
                var row = rows[i];
                if (!_ff) {
                    if (!row._parentId) {
                        _100.push(row);
                        rows.remove(row);
                        i--;
                    }
                } else {
                    if (row._parentId == _ff) {
                        _100.push(row);
                        rows.remove(row);
                        i--;
                    }
                }
            }
            var toDo = [];
            for (var i = 0; i < _100.length; i++) {
                toDo.push(_100[i]);
            }
            while (toDo.length) {
                var node = toDo.shift();
                for (var i = 0; i < rows.length; i++) {
                    var row = rows[i];
                    if (row._parentId == node[opts.idField]) {
                        if (node.children) {
                            node.children.push(row);
                        } else {
                            node.children = [row];
                        }
                        toDo.push(row);
                        rows.remove(row);
                        i--;
                    }
                }
            }
            return _100;
        }
    });
    $.fn.treegrid.defaults = $.extend({}, $.fn.datagrid.defaults, {
		pagination: false,
        treeField: null,
        animate: false,
        singleSelect: true,
        view: _c7,
        loadFilter: function(data, _101) {
            return data;
        },
        editConfig: {
            getTr: function(_102, id) {
                return $(_102).datagrid("getPanel").find("div.datagrid-body tr[node-id=" + id + "]");
            },
            getRow: function(_103, id) {
                return $(_103).treegrid("find", id);
            }
        },
        onBeforeLoad: function(row, _104) {
        },
        onLoadSuccess: function(row, data) {
        },
        onLoadError: function() {
        },
        onBeforeCollapse: function(row) {
        },
        onCollapse: function(row) {
        },
        onBeforeExpand: function(row) {
        },
        onExpand: function(row) {
        },
        onClickRow: function(row) {
        },
        onDblClickRow: function(row) {
        },
        onContextMenu: function(e, row) {
        },
        onBeforeEdit: function(row) {
        },
        onAfterEdit: function(row, _105) {
        },
        onCancelEdit: function(row) {
        }
    });
})(jQuery);

